//
//  MBProgressHUDInLoading.m
//  Init
//
//  Created by zhaoshijie on 04/04/2018.
//  Copyright © 2018 zhaoshijie. All rights reserved.
//

#import "MBProgressHUDInLoading.h"
#import "MBProgressHUD.h"
#import "UIImage+NIMGIF.h"

@implementation MBProgressHUDInLoading



/**
 加载菊花没有背景图片
 */
+ (void)MBProgressHUDInLoading
{
    
    //  移除加载
    [self MBProgressHUDInStop];
    
    [self MBProgressHUDInLoadingWithView:[UIApplication sharedApplication].keyWindow];
}



/**
 加载菊花没有背景图片

 @param view 添加背景视图
 */
+ (void)MBProgressHUDInLoadingWithView:(UIView *)view
{
    
    //  移除加载
    [self MBProgressHUDInStopWithView:view];
    
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
    hud.bezelView.style = MBProgressHUDBackgroundStyleSolidColor;
    hud.bezelView.backgroundColor = [UIColor clearColor];
}


/**
 加载菊花没有背景图片
 
 @param view 添加背景视图
 @param centerPoint 中心位置
 */
+ (void)MBProgressHUDInLoadingWithView:(UIView *)view centerPoint:(CGPoint)centerPoint
{
    
    //  移除加载
    [self MBProgressHUDInStopWithView:view];
    
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
    hud.center = centerPoint;
    hud.bezelView.style = MBProgressHUDBackgroundStyleSolidColor;
    hud.bezelView.backgroundColor = [UIColor clearColor];
}



/**
 加载菊花没有背景图片，gif图

 @param gifName gif图名称
 */
+ (void)MBProgressHUDInLoadingWithGifName:(NSString *)gifName
{
    //  移除加载
    [self MBProgressHUDInStop];
    
    [self MBProgressHUDInLoadingWithGifName:gifName view:[UIApplication sharedApplication].keyWindow];
}



/**
 加载菊花没有背景图片，gif图

 @param gifName gif图名称
 @param view 添加背景视图
 */
+ (void)MBProgressHUDInLoadingWithGifName:(NSString *)gifName view:(UIView *)view
{
    
    //  移除加载
    [self MBProgressHUDInStopWithView:view];
    
    
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
    hud.mode = MBProgressHUDModeCustomView;
    hud.bezelView.style = MBProgressHUDBackgroundStyleSolidColor;
    hud.bezelView.backgroundColor = [UIColor clearColor];
    UIImage *image = [UIImage nim_animatedGIFNamed:gifName];
    hud.customView = [[UIImageView alloc] initWithImage:image];
    hud.square = YES;
    [hud hideAnimated:YES afterDelay:3.f];
}

/**
 加载，含有文本
 
 @param title 文本
 */
+ (void)MBProgressHUDInLoadingWithTitle:(NSString *)title
{
    //  移除加载
    [self MBProgressHUDInStop];
    
    [self MBProgressHUDInLoadingWithTitle:title view:[UIApplication sharedApplication].keyWindow];
}

/**
 加载，含有文本

 @param title 文本
 @param view 背景视图
 */
+ (void)MBProgressHUDInLoadingWithTitle:(NSString *)title view:(UIView *)view
{
    
    //  移除加载
    [self MBProgressHUDInStopWithView:view];
    
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
    hud.label.text = title;
}


/**
 提示文本

 @param title 文本
 */
+ (void)MBProgressHUDInTitleWithTitle:(NSString *)title
{
    //  移除加载
    [self MBProgressHUDInStop];
    
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:[UIApplication sharedApplication].keyWindow animated:YES];
    hud.mode = MBProgressHUDModeText;
    hud.label.text = title;
    hud.label.numberOfLines = 0;
    hud.bezelView.backgroundColor = [UIColor blackColor];
    hud.label.textColor = RGBCOLOR16_ffffff;
    hud.label.font = Font_14;
    hud.center = [UIApplication sharedApplication].keyWindow.center;
    hud.userInteractionEnabled = NO;
    [hud hideAnimated:YES afterDelay:2.f];
    hud.margin = 8;
    
}


/**
 操作完成

 @param title 文本
 */
+ (void)MBProgressHUDInFinishWithTitle:(NSString *)title
{
    //  移除加载
    [self MBProgressHUDInStop];
    
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:[UIApplication sharedApplication].keyWindow animated:YES];
    hud.mode = MBProgressHUDModeCustomView;
    UIImage *image = [[UIImage imageNamed:@"Checkmark"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
    hud.customView = [[UIImageView alloc] initWithImage:image];
    hud.square = YES;
    hud.label.text = title;
    [hud hideAnimated:YES afterDelay:3.f];
}



/**
 移除加载
 */
+ (void)MBProgressHUDInStop
{
    [self MBProgressHUDInStopWithView:[UIApplication sharedApplication].keyWindow];
}



/**
 移除加载

 @param view 背景视图
 */
+ (void)MBProgressHUDInStopWithView:(UIView *)view
{
    [MBProgressHUD hideHUDForView:view animated:YES];
}

@end
